home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / RKMLibsPrgs / preferences / prefnotify.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  4KB  |  112 lines

  1. ;/* prefnotify.c.  - Execute me to compile me with SAS/C 5.10
  2. lc -cfistq -v -y -j73 prefnotify.c
  3. blink from LIB:c.o,prefnotify.o to prefnotify lib LIB:LC.lib LIB:amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. /*
  34. ** prefnotify.c - notified if serial prefs change
  35. */
  36.  
  37. #include <exec/types.h>
  38. #include <exec/memory.h>
  39. #include <dos/dos.h>
  40. #include <dos/notify.h>
  41.  
  42. #include <stdio.h>
  43.  
  44. #include <clib/exec_protos.h>
  45. #include <clib/dos_protos.h>
  46.  
  47. #ifdef LATTICE
  48. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  49. int chkabort(void) { return(0); }  /* really */
  50. #endif
  51.  
  52. #define PREFSFILENAME "ENV:sys/serial.prefs"
  53.  
  54. static UBYTE   *VersTag = "\0$VER: prefnot 37.1 (09.07.91)";
  55.  
  56. extern struct Library *DOSBase;
  57.  
  58.  
  59. void main(int argc, char **argv)
  60. {
  61. BOOL done=FALSE;
  62. struct NotifyRequest *notifyrequest;
  63. UBYTE          *filename;
  64. LONG           signum;
  65. ULONG          signals;
  66.  
  67. /* We need at least V37 for notification */
  68. if (DOSBase->lib_Version >= 37)
  69.     {
  70.     /* Allocate a NotifyRequest structure */
  71.     if (notifyrequest = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))
  72.         {
  73.         /* And allocate a signalsbit */
  74.         if ((signum = AllocSignal(-1L)) != -1)
  75.             {
  76.             /* Initialize notification request */
  77.             filename = PREFSFILENAME;
  78.             notifyrequest->nr_Name = filename;
  79.             notifyrequest->nr_Flags = NRF_SEND_SIGNAL;
  80.             /* Signal this task */
  81.             notifyrequest->nr_stuff.nr_Signal.nr_Task = (struct Task *) FindTask(NULL);
  82.             /* with this signals bit */
  83.             notifyrequest->nr_stuff.nr_Signal.nr_SignalNum = signum;
  84.  
  85.             if ((StartNotify(notifyrequest)) == DOSTRUE)
  86.                 {
  87.                 printf("Select Serial Prefs SAVE or USE to notify this program\n");
  88.                 printf("CTRL-C to exit\n\n");
  89.                 /* Loop until Ctrl-C to exit */
  90.                 while(!done)
  91.                     {
  92.                     signals = Wait(  (1L << signum) | SIGBREAKF_CTRL_C  );
  93.                     if (signals & (1L << signum))
  94.                         printf("Notification signal received.\n");
  95.                     if (signals & SIGBREAKF_CTRL_C)
  96.                         {
  97.                         EndNotify(notifyrequest);
  98.                         done=TRUE;
  99.                         }
  100.                     }
  101.                 }
  102.             else printf("Can't start notification\n");
  103.             FreeSignal(signum);
  104.             }
  105.         else printf("No signals available\n");
  106.         FreeMem(notifyrequest, sizeof(struct NotifyRequest));
  107.         }
  108.     else printf("Not enough memory for NotifyRequest.\n");
  109.     }
  110. else printf("Requires at least V37 dos.library\n");
  111. }
  112.